<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>轮播图标题修改</title>
<meta name="description"
	content="Dynamic tables and grids using jqGrid plugin" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="../assets/css/bootstrap.css" />
<link rel="stylesheet" href="../assets/css/font-awesome.css" />
<!-- page specific plugin styles -->
<link rel="stylesheet" href="../assets/css/jquery-ui.css" />
<link rel="stylesheet" href="../assets/css/jquery-ui.custom.css" />
<link rel="stylesheet" href="../assets/css/ui.jqgrid.css" />
<link rel="stylesheet" href="../assets/css/chosen.css" />
<link rel="stylesheet" href="../assets/css/daterangepicker.css " />

<!-- text fonts -->
<link rel="stylesheet" href="../assets/css/ace-fonts.css" />
<!-- ace styles -->
<link rel="stylesheet" href="../assets/css/ace.css"
	class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
			<link rel="stylesheet" href="../../../css/ace-part2.css" class="ace-main-stylesheet" />
		<![endif]-->
<!--[if lte IE 9]>
		  <link rel="stylesheet" href="../../../css/ace-ie.css" />
		<![endif]-->
    <link rel="stylesheet" href="../assets/css/page_dialog.css" />

</head>

<body class="no-skin">
	<div class="main-container" id="main-container">
		<div class="main-content">
			<div class="page-content">
				<form class="form-horizontal" id="addForm">
					
					<div class="form-group">
						<label class="col-xs-2 control-label text-right"><span class="text-danger">★</span>资讯标题：</label>
						<div class="col-xs-10">
							<div class="clearfix">
								<input type="text" class="form-control" id="title" name="title"
									placeholder="资讯标题">
								</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-2 control-label text-right"><span class="text-danger">★</span>资讯内容：</label>
						<div class="col-xs-10">
							<div class="clearfix">
									<!-- 	<textarea rows="12" cols="5" class="form-control" name="content" id="content"></textarea> -->
									<input type="hidden" name="content" id="content" value="">
										<script id="contents" name="contents" type="text/plain" style="width:100%;height:350px;"></script>
								</div>
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword" class="col-xs-2 control-label text-right"><span class="text-danger">★</span>状态：</label>
						<div class="col-xs-10">
							<div class="radio">
								<label>
									<input id="statu0" name="status" value="0" type="radio" checked class="form-control ace" />
									<span class="lbl">启用</span>
								</label>
								<label>
									<input id="statu1" name="status" value="1" type="radio" class="form-control ace" />
									<span class="lbl">禁用 </span>
								</label>
							</div>
						</div>
					</div>
					<div class="form-group text-center">
						<div class="row">
							<a id="addButton" role="button"
								class="btn btn-primary btn-sm" class="form-control">
								<span id="save"> <i class="ace-icon fa fa-floppy-o"></i>保存</span>  
								<span id="saving" hidden="true"> <i class="ace-icon fa fa-spinner fa-spin orange bigger-180"></i>正在保存...</span> 
							</a> 
							<a id="cancleButton" role="button"
								class="btn btn-danger btn-sm" class="form-control"> <i
								class="ace-icon fa  fa-times"></i>取消
							</a> 
							
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<!-- /.main-content -->

	<script type="text/javascript">
		if ('ontouchstart' in document.documentElement)
			document.write("<script src='../assets/js/jquery.mobile.custom.js'>"
					+ "<"+"/script>");
	</script>
	<script type="text/javascript" src="../assets/js/jquery1x.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap.js"></script>
	<script type="text/javascript" src="../assets/js/ace-elements.js"></script>
	<script type="text/javascript" src="../assets/js/ace.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.tips.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.form.js"></script>
	<script type="text/javascript" src="../assets/js/jquery-ui.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.ui.touch-punch.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.validate.min.js"></script>
	<script type="text/javascript" src="../assets/js/chosen.jquery.js"></script>
	<script type="text/javascript" charset="utf-8">
	var baseUrl = location.protocol  +"//"+location.host+"/";
	 window.UEDITOR_HOME_URL =baseUrl+ "manage/assets/js/ueditor/";
    </script>
	
	<script type="text/javascript" src="../assets/js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="../assets/js/ueditor/ueditor.all.js"></script>
	<script type="text/javascript" src="../assets/js/ueditor/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript">
		var LocString = String(window.document.location.href); 
		function getQueryStr(str) { 
			var rs = new RegExp("(^|)" + str + "=([^&]*)(&|$)", "gi").exec(LocString), tmp; 
			if (tmp = rs) { 
				return tmp[2]; 
			} 
			return ""; 
		} 
		var id = getQueryStr("id");
		
		var ueditor = UE.getEditor('contents',{
			  imageActionName: "d", /* 执行上传图片的action名称 */
			  imageFieldName: "attachment", /* 提交的图片表单名称 */
			  imageMaxSize: 2048000, /* 上传大小限制，单位B */
			  imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
			  imageCompressEnable: true, /* 是否压缩图片,默认是true */
			  imageCompressBorder: 1600, /* 图片压缩最长边限制 */
			  imageInsertAlign: "none", /* 插入的图片浮动方式 */
			  imageUrlPrefix: baseUrl, /* 图片访问路径前缀 */
		      serverUrl:baseUrl+"info/upload",//图片上传提交后台对应的地址
		});	
		//页面初始化
		$.post("/getInfoById", { id:id},function(response) {
			 if(response.status==0){
			$("#title").val(response.data.title);
			ueditor.ready(function() {
				ueditor.setContent(response.data.content);
			});
			$("#content").val(response.data.content);
			$("#id").val(response.data.id);
			if(response.data.status==0){
				$("#statu0").attr("checked",true);
			} else {
				$("#statu1").attr("checked",true);
			}
			
			 }
		});
		

		$("#cancleButton").click(function () {
			window.parent.Dialog.close();
		});
	
		$("#addButton").click(function () {
			$('#addForm').submit();			
			return false;
		});
		
		$('#addForm').validate({
			errorElement: 'div',
			errorClass: 'help-block',
			focusInvalid: false,
			ignore: "",
			rules: {
				title: {
					required: true
				},
				content: {
					required: true	
				}
			},
			messages: {
				title :{
					required:"请填写资讯标题！"
				},
				content :{
					required:"请填写资讯内容！"
				}
			},
			highlight: function (e) {
				$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
			},
			success: function (e) {
				$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
				$(e).remove();
			},

			errorPlacement: function (error, element) {
				if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
					var controls = element.closest('div[class*="col-"]');
					if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
					else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
				}
				else if(element.is('.chosen-select')) {
					error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
				}
				else error.insertAfter(element.parent());
			},
			submitHandler: function (form) {
				$("#addForm").ajaxSubmit({
					beforeSerialize : function(form, options) {
						$("#addButton").addClass("disabled");
						$("#save").attr("hidden",true);
						$("#saving").attr("hidden",false);
						top.showProBar();
						return true;
					},
					type : "post",
					url : "/updateInfo", // 提交的URL
					data : {id:id},
					success : function(data) {
						$("#addButton").removeClass("disabled");
			    		$("#save").attr("hidden",false);
			    		$("#saving").attr("hidden",true);
			    		top.hideProBar();
						if (data.status == 0) { // 保存成功
							$("#addButton").tips({
								side : 3,
								msg : '保存成功！',
								bg : '#AE81FF',
								time : 3
							});
							window.parent.Dialog.close();
						} else {
							$("#addButton").tips({
								side : 3,
								msg : '保存失败！请检查数据！',
								time : 3
							});
						}
					}
				});
			}
		});
	</script>
</body>
</html>
